package com.hpq.websocket;

import io.netty.util.Attribute;
import io.netty.util.AttributeKey;

import io.netty.channel.Channel;

/**
 *  Netty工具类
 */
public class NettyUtil {
    public static AttributeKey<String> TOKEN =AttributeKey.valueOf("token");
    public static AttributeKey<String> IP = AttributeKey.valueOf("ip");
    public static AttributeKey<Long> UID =  AttributeKey.valueOf("uid");
    //设置属性
    public static <T> void setAttr(Channel channel, AttributeKey<T> key, T data){
        Attribute<T>  attr = channel.attr(key);
        attr.set(data);
    }
    //获取属性
    public static <T> T getAttr(Channel channel, AttributeKey<T> ip){
        Attribute<T>  attr = channel.attr(ip);
        return attr.get();
    }
 }
